package com.imay.live.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.base.util.StringUtil;
import com.imay.live.R;
import com.imay.live.model.TextMessageModel;
import com.imay.live.utils.GlideUtil;

import java.util.List;

/**
 * Created by  nick on 2017/5/6 0006.
 * 私信记录列表
 */

public class TextMessageListAdapter extends BaseMultiItemQuickAdapter<TextMessageModel.RecordModel, BaseViewHolder> {


    public static final int ITEM_TYPE_TEXT_LEFT = 1;
    public static final int ITEM_TYPE_TEXT_RIGHT = 2;
    public static final int ITEM_TYPE_HINT = 3;
    private String leftHeadImage, rightHeadImage;

    public TextMessageListAdapter(List<TextMessageModel.RecordModel> data, String leftHeadImage, String rightHeadImage) {
        super(data);
        this.leftHeadImage = leftHeadImage;
        this.rightHeadImage = rightHeadImage;
        addItemType(ITEM_TYPE_TEXT_LEFT, R.layout.item_chat_text_left);
        addItemType(ITEM_TYPE_TEXT_RIGHT, R.layout.item_chat_text_right);
        addItemType(ITEM_TYPE_HINT, R.layout.item_chat_hint_center);
    }

    @Override
    protected void convert(BaseViewHolder helper, TextMessageModel.RecordModel item) {
        switch (item.getItemType()) {
            case ITEM_TYPE_TEXT_LEFT:
                helper.setText(R.id.tv_time_chat_text_left, item.getShowTime());
                helper.setVisible(R.id.tv_time_chat_text_left, !StringUtil.isEmpty(item.getShowTime()));
                helper.setText(R.id.tv_content_chat_text_left, item.getContent());
                ImageView iv_head_img_chat_text_left = helper.getView(R.id.iv_head_img_chat_text_left);
                GlideUtil.loadCircleImage(iv_head_img_chat_text_left, TextUtils.isEmpty(leftHeadImage) ? item.getHeadImg() : leftHeadImage, R.mipmap.pnl_00_head108);
                helper.addOnClickListener(R.id.iv_head_img_chat_text_left);
                helper.addOnLongClickListener(R.id.tv_content_chat_text_left);
                break;
            case ITEM_TYPE_TEXT_RIGHT:
                helper.setText(R.id.tv_time_chat_text_right, item.getShowTime());
                helper.setVisible(R.id.tv_time_chat_text_right, !StringUtil.isEmpty(item.getShowTime()));
                helper.setText(R.id.tv_content_chat_text_right, item.getContent());
                ImageView iv_head_img_chat_text_right = helper.getView(R.id.iv_head_img_chat_text_right);
                GlideUtil.loadCircleImage(iv_head_img_chat_text_right, TextUtils.isEmpty(rightHeadImage) ? item.getHeadImg() : rightHeadImage, R.mipmap.pnl_00_head108);
                helper.addOnClickListener(R.id.iv_head_img_chat_text_right);
                helper.addOnLongClickListener(R.id.tv_content_chat_text_right);


                break;
            case ITEM_TYPE_HINT:
                helper.setText(R.id.tv_time_chat_text_center, item.getShowTime());
                helper.setVisible(R.id.tv_time_chat_text_center, !StringUtil.isEmpty(item.getShowTime()));
                if (item.getUid() == -1) {
                    helper.setText(R.id.tv_chat_hint, item.getContent());
                } else {
                    helper.setText(R.id.tv_chat_hint, R.string.first_chat_hint);
                }
                break;

        }
    }
}
